package top.mcwebsite.playandroid.business.home.impl.vm


import top.mcwebsite.playandroid.common.user.api.IUserService
import top.mcwebsite.playandroid.lib.mvi.base.BaseViewModel
import top.mcwebsite.playandroid.lib.servicemanager.core.ServiceManager

class MainViewModel : BaseViewModel<MainIntent, MainUiState, MainUiEffect>(
    defaultState = MainUiState()
) {
    override fun handleIntent(intent: MainIntent) {
        when (intent) {
            is MainIntent.GoMessageIntent -> {
                if (ServiceManager.getService<IUserService>().isLogin()) {
                    sendUiEffect(MainUiEffect.GoNotificationUiEffect)
                } else {
                    sendUiEffect(MainUiEffect.NavigationToLoginUiEffect)
                }
            }
            is MainIntent.GoSearchIntent -> {
                sendUiEffect(MainUiEffect.GoSearchUiEffect)
            }
            is MainIntent.OnTabClickIntent -> {
                setUiState { copy(currentTab = intent.mainTabItem) }
            }
            is MainIntent.OnHorizontalScrolledIntent -> {
                setUiState { copy(currentTab = intent.mainTabItem) }
            }
        }
    }
}
